import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";
/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect"),
      },
    ],
  },
  {
    path: "/login",
    component: () => import("@/views/login"),
    hidden: true,
  },
  {
    path: "/register",
    component: () => import("@/views/register"),
    hidden: true,
  },
  {
    path: "/404",
    component: () => import("@/views/error/404"),
    hidden: true,
  },
  {
    path: "/401",
    component: () => import("@/views/error/401"),
    hidden: true,
  },
  //2023/08/09
  // {
  //   path: "",
  //   component: Layout,
  //   redirect: "index",
  //   children: [
  //     {
  //       path: "index",
  //       component: () => import("@/views/index"),
  //       name: "Index",
  //       meta: { title: "首页", icon: "home", affix: true },
  //     },
  //   ],
  // },
  // {
  //   path: "",
  //   component: Layout,
  //   redirect: "/configuration/resource/manage",
  //   // children: [
  //   //   {
  //   //     path: "index",
  //   //     component: () => import("@/views/index"),
  //   //     name: "Index",
  //   //     meta: { title: "首页", icon: "home", affix: true },
  //   //   },
  //   // ],
  // },
  // {
  //   path: "/",
  //   component: Layout,
  //   redirect: "/configuration/resource/manage",
  //   // children: [
  //   //   {
  //   //     path: "index",
  //   //     component: () => import("@/views/index"),
  //   //     name: "Index",
  //   //     meta: { title: "首页", icon: "home", affix: true },
  //   //   },
  //   // ],
  // },
  {
    path: "/tool",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "build/index",
        component: () => import("@/views/tool/build/index"),
        name: "FormBuild",
        meta: { title: "表单设计", icon: "" },
      },
    ],
  },
  {
    path: "/user",
    component: Layout,
    hidden: true,
    redirect: "noredirect",
    children: [
      {
        path: "profile",
        component: () => import("@/views/system/user/profile/index"),
        name: "Profile",
        meta: { title: "个人中心", icon: "user" },
      },
    ],
  },
  //自动化管理
  // {
  //   path: "/automated",
  //   name: "Automated",
  //   component: Layout,
  //   redirect: "noRedirect",
  //   hidden: true,
  //   meta: { title: "自动化管理", icon: "automated-management" },
  //   children: [
  //     {
  //       path: "Intelligent",
  //       hidden: true, //不显示
  //       name: "Intelligent",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       redirect: "/automated/Intelligent/host",
  //       meta: { title: "智能化运维", icon: "user", IsRouter: true, activeMenu: "/automated" },
  //       children: [
  //         {
  //           path: "host",
  //           name: "Host",
  //           component: () => import("@/views/AutomatedManagement/Intelligent/Monitor/Host.vue"),
  //           meta: { title: "主机", activeMenu: "/automated/Intelligent" },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // //配置管理
  // {
  //   path: "/configuration",
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: { title: "配置管理", icon: "configuration-management" },
  //   children: [
  //     //业务
  //     {
  //       path: "business",
  //       name: "Business",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "业务", icon: "business" },
  //       children: [
  //         {
  //           path: "topology",
  //           name: "Topology",
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Business_Topology.vue"
  //             ),
  //           meta: { title: "业务拓扑" },
  //         },
  //         {
  //           path: "topology_info",
  //           name: "Topology_Info",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Topology_Info.vue"
  //             ),
  //           meta: {
  //             title: "业务拓扑详情",
  //             activeMenu: "/configuration/business/topology",
  //           },
  //         },
  //         {
  //           path: "addhost",
  //           name: "AddHost",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/AddHost.vue"
  //             ),
  //           meta: {
  //             title: "添加主机",
  //             activeMenu: "/configuration/business/topology",
  //           },
  //         },
  //         {
  //           path: "cluster_info",
  //           name: "Cluster_Info",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Cluster_Info.vue"
  //             ),
  //           meta: {
  //             title: "集群详情",
  //             activeMenu: "/configuration/business/cluster",
  //           },
  //         },
  //         {
  //           path: "servicetemplate",
  //           name: "Servicetemplate",
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Service_Template.vue"
  //             ),
  //           meta: { title: "服务模板" },
  //         },
  //         {
  //           path: "Template_Info",
  //           name: "Template_Info",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Template_Info.vue"
  //             ),
  //           meta: {
  //             title: "服务模板详情",
  //             activeMenu: "/configuration/business/servicetemplate",
  //           },
  //         },
  //         {
  //           path: "cluster",
  //           name: "Cluster",
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Cluster_Template.vue"
  //             ),
  //           meta: { title: "集群模版" },
  //         },
  //         {
  //           path: "classification",
  //           name: "Classification",
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/business/Service_Classification.vue"
  //             ),
  //           meta: { title: "服务分类" },
  //         },
  //       ],
  //     },
  //     //资源
  //     {
  //       path: "resource",
  //       // hidden: true, //不显示
  //       name: "Resource",
  //       redirect: "noRedirect",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "资源", icon: "resource" },
  //       children: [
  //         {
  //           path: "catalogue",
  //           name: "Catalogue",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/resource/Catalogue.vue"),
  //           meta: { title: "资源目录" },
  //         },
  //         {
  //           path: "business",
  //           name: "BusinessManage",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/resource/Business.vue"),
  //           meta: { title: "业务管理" },
  //         },
  //         {
  //           path: "business_info",
  //           name: "Business_Info",
  //           hidden: true,
  //           component: () =>
  //             import("@/views/ConfigurationManagement/resource/Business_Info.vue"),
  //           meta: {
  //             title: "业务管理详情",
  //             activeMenu: "/configuration/resource/business",
  //           },
  //         },
  //         {
  //           path: "host",
  //           name: "Host",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/resource/Host.vue"),
  //           meta: { title: "主机管理" },
  //         },
  //         {
  //           path: "hostDetail",
  //           name: "HostDetail",
  //           hidden: true,
  //           component: () =>
  //             import("@/views/ConfigurationManagement/business/Topology_Info.vue"),
  //           meta: { title: "主机详情", activeMenu: "/configuration/resource/host" },
  //         },
  //         {
  //           path: "catalogueInfo",
  //           name: "CatalogueInfo",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/resource/Catalogue_Info.vue"
  //             ),
  //           meta: {
  //             title: "资源信息",
  //             activeMenu: "/configuration/resource/catalogue",
  //           },
  //         },
  //         {
  //           path: "catalogueDetail",
  //           name: "CatalogueDetail",
  //           hidden: true,
  //           component: () =>
  //             import(
  //               "@/views/ConfigurationManagement/resource/Catalogue_Detail.vue"
  //             ),
  //           meta: {
  //             title: "资源实例详情",
  //             activeMenu: "/configuration/resource/catalogue",
  //           },
  //         },
  //       ],
  //     },
  //     //模型
  //     {
  //       path: "model",
  //       // hidden: true, //不显示
  //       name: "Model",
  //       redirect: "noRedirect",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "模型", icon: "model" },
  //       children: [
  //         {
  //           path: "manage",
  //           name: "Manage",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/model/Manage.vue"),
  //           meta: { title: "模型管理" },
  //         },
  //         {
  //           path: "relation",
  //           name: "Relation",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/model/Relation.vue"),
  //           meta: { title: "模型关系" },
  //         },
  //         {
  //           path: "association",
  //           name: "Association",
  //           component: () =>
  //             import("@/views/ConfigurationManagement/model/Association.vue"),
  //           meta: { title: "关联类型" },
  //         },
  //         {
  //           path: "modelDetail",
  //           name: "ModelDetail",
  //           hidden: true,
  //           component: () =>
  //             import("@/views/ConfigurationManagement/model/Model_Detail.vue"),
  //           meta: {
  //             title: "模型详情",
  //             activeMenu: "/configuration/model/manage",
  //           },
  //         },
  //       ],
  //     },
  //   ],
  // },

  // //流程管理

  // //自动化管理
  // {
  //   path: "/automated",
  //   name: "Automated",
  //   component: Layout,
  //   redirect: "/automated/A/A1",
  //   meta: { title: "自动化管理", icon: "automated-management" },
  //   children: [
  //     {
  //       path: "A",
  //       name: "Automated_A",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单A", icon: "user" },
  //       children: [
  //         {
  //           path: "A1",
  //           name: "Automated_A1",
  //           component: () => import("@/views/AutomatedManagement/A/A1.vue"),
  //           meta: { title: "菜单A_1" },
  //         },
  //         {
  //           path: "A2",
  //           name: "Automated_A2",
  //           component: () => import("@/views/AutomatedManagement/A/A2.vue"),
  //           meta: { title: "菜单A_2" },
  //         },
  //       ],
  //     },
  //     {
  //       path: "B",
  //       // hidden: true, //不显示
  //       name: "Automated_B",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单B", icon: "user" },
  //       children: [
  //         {
  //           path: "B1",
  //           name: "Automated_B1",
  //           component: () => import("@/views/AutomatedManagement/B/B2.vue"),
  //           meta: { title: "菜单B_1" },
  //         },
  //         {
  //           path: "B2",
  //           name: "Automated_B2",
  //           component: () => import("@/views/AutomatedManagement/B/B2.vue"),
  //           meta: { title: "菜单B_2" },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // //数据展示
  // {
  //   path: "/dataPresentation",
  //   name: "DataPresentation",
  //   component: Layout,
  //   redirect: "/dataPresentation/A/A1",
  //   meta: { title: "数据展示", icon: "data-show" },
  //   children: [
  //     {
  //       path: "A",
  //       name: "DataPresentation_A",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单A", icon: "user" },
  //       children: [
  //         {
  //           path: "A1",
  //           name: "DataPresentation_A1",
  //           component: () => import("@/views/DataPresentation/A/A1.vue"),
  //           meta: { title: "菜单A_1" },
  //         },
  //         {
  //           path: "A2",
  //           name: "DataPresentation_A2",
  //           component: () => import("@/views/DataPresentation/A/A2.vue"),
  //           meta: { title: "菜单A_2" },
  //         },
  //       ],
  //     },
  //     {
  //       path: "B",
  //       // hidden: true, //不显示
  //       name: "DataPresentation_B",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单B", icon: "user" },
  //       children: [
  //         {
  //           path: "B1",
  //           name: "DataPresentation_B1",
  //           component: () => import("@/views/DataPresentation/B/B2.vue"),
  //           meta: { title: "菜单B_1" },
  //         },
  //         {
  //           path: "B2",
  //           name: "DataPresentation_B2",
  //           component: () => import("@/views/DataPresentation/B/B2.vue"),
  //           meta: { title: "菜单B_2" },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // //分级授权
  // {
  //   path: "/hierarchical",
  //   name: "Hierarchical",
  //   component: Layout,
  //   redirect: "/hierarchical/A/A1",
  //   meta: { title: "分级授权", icon: "Hierarchical_Authorization" },
  //   children: [
  //     {
  //       path: "A",
  //       name: "Hierarchical_A",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单A", icon: "user" },
  //       children: [
  //         {
  //           path: "A1",
  //           name: "Hierarchical_A1",
  //           component: () =>
  //             import("@/views/HierarchicalAuthorization/A/A1.vue"),
  //           meta: { title: "菜单A_1" },
  //         },
  //         {
  //           path: "A2",
  //           name: "Hierarchical_A2",
  //           component: () =>
  //             import("@/views/HierarchicalAuthorization/A/A2.vue"),
  //           meta: { title: "菜单A_2" },
  //         },
  //       ],
  //     },
  //     {
  //       path: "B",
  //       // hidden: true, //不显示
  //       name: "Hierarchical_B",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单B", icon: "user" },
  //       children: [
  //         {
  //           path: "B1",
  //           name: "Hierarchical_B1",
  //           component: () =>
  //             import("@/views/HierarchicalAuthorization/B/B2.vue"),
  //           meta: { title: "菜单B_1" },
  //         },
  //         {
  //           path: "B2",
  //           name: "Hierarchical_B2",
  //           component: () =>
  //             import("@/views/HierarchicalAuthorization/B/B2.vue"),
  //           meta: { title: "菜单B_2" },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // //集中管理
  // {
  //   path: "/centralized",
  //   name: "Centralized",
  //   component: Layout,
  //   redirect: "/centralized/A/A1",
  //   meta: { title: "集中管理", icon: "Centralized_Management" },
  //   children: [
  //     {
  //       path: "A",
  //       name: "Centralized_A",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单A", icon: "user" },
  //       children: [
  //         {
  //           path: "A1",
  //           name: "Centralized_A1",
  //           component: () => import("@/views/CentralizedManagement/A/A1.vue"),
  //           meta: { title: "菜单A_1" },
  //         },
  //         {
  //           path: "A2",
  //           name: "Centralized_A2",
  //           component: () => import("@/views/CentralizedManagement/A/A2.vue"),
  //           meta: { title: "菜单A_2" },
  //         },
  //       ],
  //     },
  //     {
  //       path: "B",
  //       // hidden: true, //不显示
  //       name: "Centralized_B",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单B", icon: "user" },
  //       children: [
  //         {
  //           path: "B1",
  //           name: "Centralized_B1",
  //           component: () => import("@/views/CentralizedManagement/B/B2.vue"),
  //           meta: { title: "菜单B_1" },
  //         },
  //         {
  //           path: "B2",
  //           name: "Centralized_B2",
  //           component: () => import("@/views/CentralizedManagement/B/B2.vue"),
  //           meta: { title: "菜单B_2" },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // //干网管理
  // {
  //   path: "/backbone",
  //   name: "Backbone",
  //   component: Layout,
  //   redirect: "/backbone/A/A1",
  //   meta: { title: "干网管理", icon: "Dry_network_management" },
  //   children: [
  //     {
  //       path: "A",
  //       name: "Backbone_A",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单A", icon: "user" },
  //       children: [
  //         {
  //           path: "A1",
  //           name: "Backbone_A1",
  //           component: () => import("@/views/BackboneManagement/A/A1.vue"),
  //           meta: { title: "菜单A_1" },
  //         },
  //         {
  //           path: "A2",
  //           name: "Backbone_A2",
  //           component: () => import("@/views/BackboneManagement/A/A2.vue"),
  //           meta: { title: "菜单A_2" },
  //         },
  //       ],
  //     },
  //     {
  //       path: "B",
  //       // hidden: true, //不显示
  //       name: "Backbone_B",
  //       component: () => import("@/layout/components/AppMain.vue"),
  //       meta: { title: "菜单B" },
  //       children: [
  //         {
  //           path: "B1",
  //           name: "Backbone_B1",
  //           component: () => import("@/views/BackboneManagement/B/B2.vue"),
  //           meta: { title: "菜单B_1" },
  //         },
  //         {
  //           path: "B2",
  //           name: "Backbone_B2",
  //           component: () => import("@/views/BackboneManagement/B/B2.vue"),
  //           meta: { title: "菜单B_2" },
  //         },
  //       ],
  //     },
  //   ],
  // },

  //系统管理
  //系统工具
  //办公管理

];
// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: "/system/user-auth",
    component: Layout,
    hidden: true,
    permissions: ["system:user:edit"],
    children: [
      {
        path: "role/:userId(\\d+)",
        component: () => import("@/views/system/user/authRole"),
        name: "AuthRole",
        meta: { title: "分配角色", activeMenu: "/system/user" },
      },
    ],
  },
  {
    path: "/system/role-auth",
    component: Layout,
    hidden: true,
    permissions: ["system:role:edit"],
    children: [
      {
        path: "user/:roleId(\\d+)",
        component: () => import("@/views/system/role/authUser"),
        name: "AuthUser",
        meta: { title: "分配用户", activeMenu: "/system/role" },
      },
    ],
  },
  {
    path: "/system/dict-data",
    component: Layout,
    hidden: true,
    permissions: ["system:dict:list"],
    children: [
      {
        path: "index/:dictId(\\d+)",
        component: () => import("@/views/system/dict/data"),
        name: "Data",
        meta: { title: "字典数据", activeMenu: "/system/dict" },
      },
    ],
  },
  {
    path: "/system/oss-config",
    component: Layout,
    hidden: true,
    permissions: ["system:oss:list"],
    children: [
      {
        path: "index",
        component: () => import("@/views/system/oss/config"),
        name: "OssConfig",
        meta: { title: "配置管理", activeMenu: "/system/oss" },
      },
    ],
  },
  {
    path: "/tool/gen-edit",
    component: Layout,
    hidden: true,
    permissions: ["tool:gen:edit"],
    children: [
      {
        path: "index/:tableId(\\d+)",
        component: () => import("@/views/tool/gen/editTable"),
        name: "GenEdit",
        meta: { title: "修改生成配置", activeMenu: "/tool/gen" },
      },
    ],
  },
  {
    path: "/workflow/process",
    component: Layout,
    hidden: true,
    permissions: ["workflow:process:query"],
    children: [
      {
        path: "start/:deployId([\\w|\\-]+)",
        component: () => import("@/views/workflow/work/start"),
        name: "WorkStart",
        meta: { title: "发起流程", icon: "" },
      },
      {
        path: "claimStart/:deployId([\\w|\\-]+)",
        component: () => import("@/views/workflow/work/claimStart"),
        name: "WorkClaimStart",
        meta: { title: "发起流程", icon: "" },
      },
      {
        path: "eventStart",
        component: () => import("@/views/workflow/work/eventStart"),
        name: "WorkClaimStart",
        meta: { title: "发起流程", icon: "" },
      },
      {
        path: "detail/:procInsId([\\w|\\-]+)",
        component: () => import("@/views/workflow/work/detail"),
        name: "WorkDetail",
        meta: { title: "流程详情", activeMenu: "/work/own" },
      },
    ],
  },
];

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch((err) => err);
};
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch((err) => err);
};

export default new Router({
  base: process.env.VUE_APP_CONTEXT_PATH,
  mode: "history", // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
});
